<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // function sleep(ms) {

    //   var start = Date.now()
    //   var end = start + ms
    //   while (Date.now() < end) {
    //     alert("1111")
    //   }
    //   return
    // }

    // sleep(1000)

    //promise实现


    // function sleep(ms) {
    //   var temple = new Promise((resolve) => {
    //     console.log(111);
    //     setTimeout(resolve, ms)

    //   })

    //   return temple
    // }

    // sleep(1000).then(() => {
    //   console.log(222);

    // })


    function sleep(ms) {
      var temple = new Promise(function (resolve, reject) {

        console.log(111);
        setTimeout(function () {
          resolve()
        }, ms)

      })

      return temple
    }

    sleep(1000).then(() => {
      console.log(222);

    })
  </script>
</body>

</html>